//设置token
export const setToken= (state, data)=>{
    state.token = data;
}

// 添加tabs
export const addTabs =(state, data)=> {
    console.log("add tab"+data)
    state.openTab.push(data);
}
// 更新tabs
export const updateTabs =(state, data)=> {
    console.log("update tab"+data)
    for (let item of state.openTab) {
        if (item.path === data.path) {
            item.name=data.name;
        }
    }
}
// 删除tabs
export const deleteTabs =(state, path) =>{
    let index = 0;
    for (let option of state.openTab) {
        if (option.path === path) {
            break;
        }
        index++;
    }
    state.openTab.splice(index, 1);
}
// 设置当前激活的菜单
export const setActiveMenu= (state, menu)=>{
    state.activeMenu = menu;
}
//添加micro
export const addMicro =(state, data)=> {
    console.log("add micro"+data)
    state.microList.push(data);
}
//更新micro
export const updateMicro =(state, data)=> {
    console.log("update micro"+data)
    for (let item of state.microList) {
        if (item.activeRule === data.activeRule) {
            item=data;
        }
    }
}
//删除micro
export const deleteMicro =(state, activeRule) =>{
    console.log("delete micro"+activeRule)
    let index = 0;
    for (let item of state.microList) {
        //console.log(item.activeRule)
        if (item.activeRule === activeRule) {
            break;
        }
        index++;
    }
    state.microList.splice(index, 1);
}
//设置当前micro
export const setCurrentMicro= (state, data)=>{
    state.currentMicro = data;
}
//添加可缓存的组件
export const addViewIncludes= (state, data)=>{
    let viewIncludes=  state.viewIncludes ;
    let arr=viewIncludes.split(",");
    let cName=arr.find(item => item===data);
    if (!cName){
        viewIncludes=viewIncludes+data+",";
        state.viewIncludes=viewIncludes;
        console.log("addViewIncludes",data)
    }
}
//删除可缓存的组件
export const deleteViewIncludes= (state, data)=>{
    let viewIncludes=  state.viewIncludes ;
    viewIncludes=viewIncludes.replace(data+",","")
    state.viewIncludes=viewIncludes;
    console.log("deleteViewIncludes",data)
}


